package cn.topevery.garden.dal.logic;

import cn.topevery.garden.dal.dao.ClockInPeopleDao;
import cn.topevery.garden.entity.po.ClockInPeople;
import cn.topevery.garden.entity.query.ClockInPeopleQuery;
import cn.topevery.garden.entity.vo.ClockInPeopleVO;
import cn.topevery.garden.framework.base.BaseLogic;
import hw.topevery.framework.Utility;
import hw.topevery.framework.db.base.BaseEntityDao;
import hw.topevery.framework.db.entity.DataPager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 人员打卡记录表
 *
 * @author code-generate
 * @date 2022-01-12
 */
@Service
public class ClockInPeopleLogic extends BaseLogic<ClockInPeople> {
    @Autowired
    ClockInPeopleDao clockInPeopleDao;

    @Override
    public BaseEntityDao<ClockInPeople, Integer> getDao() {
        return clockInPeopleDao;
    }


    /**
     * 获取列表
     *
     * @param query
     */
    public DataPager<ClockInPeopleVO> listPage(ClockInPeopleQuery query) {
        return clockInPeopleDao.listPage(query);
    }

    /**
     * 根据自增id批量删除
     *
     * @param ids
     */
    public void deleteBatchById(String userId, Integer[] ids) {
        clockInPeopleDao.delete(userId, ids);
    }

    /**
     * 根据自增id保存或者更新
     *
     * @param clockInPeople 实体
     */
    public void saveOrUpdate(String userId, ClockInPeople clockInPeople) {
        clockInPeopleDao.saveOrUpdate(userId, clockInPeople);
    }

    /**
     * 根据自定义列值来获取对象
     */
    public ClockInPeople getEntityByColumn(String key, String value) {
        return clockInPeopleDao.getEntityByColumn(key, value);
    }

    /**
     * 新增每天的考勤记录
     *
     * @param
     * @return
     * @创建人 dong.zou
     * @创建时间 2022/1/12
     */
    public Boolean insertClock() {
        return clockInPeopleDao.insertClock();
    }

    /**
     * 更新每天的考勤记录
     *
     * @param
     * @return
     * @创建人 dong.zou
     * @创建时间 2022/1/12
     */
    public Boolean UpDateInClock() {
        return clockInPeopleDao.UpDateInClock();
    }


    /**
     * @return
     * @query 片区出勤统计
     * @创建人 dong.zou
     * @创建时间 2022/1/25
     */
    public List<Map<String, Object>> getExtentWorkCountList(ClockInPeopleQuery query) {
        List<Map<String, Object>> ls  =clockInPeopleDao.getExtentWorkCountList(query);
        return ls;
    }

    /**
     *
     * @query 人员出勤统计
     * @return
     * @创建人 dong.zou
     * @创建时间 2022/1/25
     */
    public List<Map<String, Object>> getPeopleWorkCountList(ClockInPeopleQuery query) {

        List<Map<String, Object>> ls  =clockInPeopleDao.getPeopleWorkCountList(query);
       for (int i = 0;i<ls.size();i++){
           Map m =  ls.get(i);
           int valid = Integer.parseInt(m.get("c_valid_time").toString());
           m.put("c_valid_time_str" ,Utility.GetTimeString(valid));
       }
        return ls;
    }

}
